<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf"
         unique-identifier="project-<%= config.project %>"
         version="3.0">
  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:title><%= config.project %> - <%= config.version %></dc:title>
    <dc:identifier id="project-<%= config.project %>"><%= uuid %></dc:identifier>
    <dc:language><%= config.language %></dc:language>
    <%= for {author, index} <- Enum.with_index(config.authors || [], 1) do %>
      <dc:creator id="author<%= index %>"><%= author %></dc:creator>
    <% end %>
    <meta property="dcterms:modified"><%= datetime %></meta>
    <%= if config.cover do %>
      <meta name="cover" content="cover-image"/>
    <% end %>
  </metadata>
  <manifest>
    <item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav scripted"/>
    <item id="cover" href="title.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
    <%= for {_title, extras} <- config.extras, extra <- extras do %>
      <item id="<%= URI.encode extra.id %>" href="<%= URI.encode extra.id %>.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
    <% end %>
    <%= for filter <- [:modules, :tasks], node <- nodes[filter] do %>
      <item id="<%= URI.encode node.id %>" href="<%= URI.encode node.id %>.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
    <% end %>
    <%= for {static_file, media_type} <- static_files do %>
      <item id="<%= static_file_to_id(static_file) %>" href="<%= static_file %>" media-type="<%= media_type %>"/>
    <% end %>
    <%= if config.cover do %>
      <item id="cover-image" href="assets/cover<%= Path.extname(config.cover) %>" media-type="<%= media_type(Path.extname(config.cover)) %>"/>
    <% end %>
    <%= if config.logo do %>
      <item id="logo" href="assets/logo<%= Path.extname(config.logo) %>" media-type="<%= media_type(Path.extname(config.logo)) %>"/>
    <% end %>
  </manifest>
  <spine>
    <itemref idref="cover"/>
    <itemref idref="nav"/>
    <%= for {_title, extras} <- config.extras, extra <- extras do %>
      <itemref idref="<%= URI.encode extra.id %>"/>
    <% end %>
    <%= for filter <- [:modules, :tasks], node <- nodes[filter] do %>
      <itemref idref="<%= URI.encode node.id %>"/>
    <% end %>
  </spine>
</package>
